######################################################################
##                
## Copyright (C) 2004, 2007,  Karlsruhe University
##                
## File path:     Makefile.in
## Description:   Build a bootable disk image
## 
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## are met:
## 1. Redistributions of source code must retain the above copyright
##    notice, this list of conditions and the following disclaimer.
## 2. Redistributions in binary form must reproduce the above copyright
##    notice, this list of conditions and the following disclaimer in the
##    documentation and/or other materials provided with the distribution.
## 
## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
## ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
## SUCH DAMAGE.
## 
## $Id: Makefile.in,v 1.1 2006/11/24 15:46:44 ud3 Exp $
## 
######################################################################

srcdir=		.
top_srcdir=	../..
top_builddir=	../..

APP=${top_builddir}/apps/bench/pingpong/pingpong

include $(top_srcdir)/Mk/l4.base.mk

do-all:	bootdisk.img

bootdisk.img:	grub.img mtoolsrc ${srcdir}/menu.lst ${top_builddir}/util/kickstart/kickstart ${top_builddir}/serv/sigma0/sigma0  \
		${APP} ${kerneldir}/${KERNEL}
	@# Create a disk image
	/sbin/mkdosfs -C bootdisk.img 1440
	@# Make it a GRUB disk
	dd if=grub.img of=bootdisk.img conv=notrunc > /dev/null
	#@ Strip binaries
	strip ${top_builddir}/*/*/{kickstart,sigma0} 
	strip ${APP}
	cp ${kerneldir}/${KERNEL} ${kerneldir}/${KERNEL}.stripped
	strip ${kerneldir}/${KERNEL}.stripped 
	cat ${srcdir}/menu.lst | sed -e "s/APP/`basename ${APP}`/" > menu.lst
	@# Copy the binaries to it
	export MTOOLSRC=mtoolsrc ; \
	 mcopy -m menu.lst y:boot/grub ; \
	 mcopy -m ${top_builddir}/*/*/{kickstart,sigma0} y: ; \
	 mcopy -m ${APP} y: ; \
	 mcopy -m ${kerneldir}/${KERNEL}.stripped y:kernel

grub.img:
	# Fetch GRUB disk image from web if not local
	wget -O grub.img "http://i30www.ira.uka.de/~ud3/mkgrubdisk/makegrubbootdisk2.cgi?MENUPATH=/boot/grub/menu.lst"

mtoolsrc:
	echo 'drive y: file="bootdisk.img"' > $@


do-clean:
	@$(RM) bootdisk.img mtoolsrc ${KERNEL}.stripped
